package com.example.mapper.one_to_many;

import com.example.bean.Classes;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @program: mybatis_maven
 * @description:
 * @author: zhanghz001
 * @create: 2020-11-10 19:52
 **/
public interface ClassesMapper {
    @Select({"select  c.id   cid,\n" +
            "       c.NAME cname\n" +
            "from classes c\n" +
            "where c.id=#{id};"})
    @Results(
            id = "classes",
            value = {@Result(
                    property = "id",
                    column = "cid"
            ), @Result(
                    property = "name",
                    column = "cname"
            ), @Result(
                    /*
                       // 被包含对象的变量名
                    // 被包含对象的实际数据类型
                          // 根据查询出的classes表的id字段来查询student表
                        many、@Many 一对多查询的固定写法
                        select属性：指定调用哪个接口中的哪个查询方法
                     */
                    property = "students",
                    column = "cid",
                    javaType = List.class,
                    many = @Many(select = "com.example.mapper.StudentMapper3.selectByCid")
            )}
    )
    Classes selectById(Integer id);

}
